<?php

namespace app\admin\controller;

use think\Controller;
use app\admin\model\AdminLogin;
use think\facade\Session;

class Common extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->check_login();
    }

    public function check_login()
    {


        //如果cookie不存在。调到登录页
        if (!isset($_COOKIE['token'])) {
            $this->error('您还没有登录，请登录',url('/admin/login'));
        }

        //如果cookie与数据库的不匹配，表示用户伪造了tooken
        $token = $_COOKIE['token'];
        $user = AdminLogin::where("token = '$token'")->find();
        if (!$user) {
            $this->error('请不要非法登录',url('/admin/login'));
        }


    }

}